package com.hqyj.server.util;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
//自定义加密工具类
public class CryptoUtil {

    //@Value("${freemvoie.md5-salt}")
   //private String md5Salt; //m5的盐

    private static String md5Salt;

    @Value("${freemoive.md5-salt}")
    private void setMd5Salt(String salt){
        CryptoUtil.md5Salt = salt;
    }

    //对密码进行MD5+Salt进行加密
    public static String md5BySalt(String password) throws Exception{
        Digester md5 = new Digester(DigestAlgorithm.MD5);
        md5.setSalt(md5Salt .getBytes("utf-8")); //加盐了

        return md5.digestHex(password);
    }
}
